package com.eds.sms.controller;


import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
import com.eds.pojo.BaseResult;
import com.eds.sms.domain.SmsCode;
import com.eds.sms.utils.SmsSendUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SmsController {
    //发送短信验证码
    @GetMapping("/sms/sendSmsCode")
    public BaseResult sendSmsCode(String phone, String code)  {
        try {
            //发送短信
            SendSmsResponse resp = SmsSendUtils.sendSms(phone, new ObjectMapper().writeValueAsString(new SmsCode(code)));
            BaseResult result = new BaseResult(resp.getStatusCode(), resp.getBody().getMessage(), null, null);
            return result;
        } catch (Exception e) {
            BaseResult result = new BaseResult(400, "验证码发送失败", null, null);
            return result;
        }
    }
}
